#ifndef _Included_net_routeyo_im_api_Im4c_H_
#define _Included_net_routeyo_im_api_Im4c_H_

#include "approxy4esp.h"
#include "cJSON.h"
#define MsgType_


#define IM_MsgType_Event  10
#define IM_MsgType_Text  11
#define IM_MsgType_Audio  12
#define IM_MsgType_Img  13
#define IM_MsgType_Loc  14
#define IM_MsgType_Video  15
#define IM_MsgType_File  16
#define IM_MsgType_Link  17

typedef struct UserNameST{
		char* szUserName;
		char* szUserAgent;
		char* szUid;
		char* szSid;
		char* szAccessToken;
		char* szWebCtxPath;
		int nUserNameLen;
		int nUserAgentLen;
		int nUid;
		int nSid;
		int nAccessToken;
		int nWebCtxPath;
	} UserNameST_t;

typedef struct IMHandleST
{
	char *json;
	int json_len;
	long channelID;
}IMHandleST_t;
	typedef struct IMEventST{
		int nMsgType;
		char * szMsgID;
		char * szSenderAgent;
		char * szSenderAgentName;
		char * szSenderAgentAvatar;
		char * szRecvTime;
		char * szEventKey;
		char * szEventName;
		char * szEventObj;
		int nMsgID;
		int nSenderAgent;
		int nSenderAgentName;
		int nSenderAgentAvatar;
		int nRecvTime;
		int nEventKey;
		int nEventName;
		int nEventObj;
		char * szRecvierAgent;
		int nRecvierAgent;
		int ncb;
		char * ncb_url;
		int channelID;
	} IMEventST_t;

	typedef struct IMTextST{
		int nMsgType;
		char * szMsgID;
		char * szSenderAgent;
		char * szRecvTime;
		char * szText;
		int nMsgID;
		int nSenderAgent;
		int nRecvTime;
		int nText;
		char * szRecvierAgent;
		int nRecvierAgent;
	} IMTextST_t;

	typedef struct IMLocationST{
		int nMsgType;
		char * szMsgID;
		char * szSenderAgent;
		char * szRecvTime;
		char * szLocX;
		char * szLocY;
		char * szLabel;
		int nMsgID;
		int nSenderAgent;
		int nRecvTime;
		int nLocX;
		int nLocY;
		int nLabel;
		char * szRecvierAgent;
		int nRecvierAgent;
	} IMLocationST_t;

	typedef struct IMMediaST{
		int nMsgType;
		char * szMsgID;
		char * szSenderAgent;
		char * szRecvTime;
		char * szMediaID;
		char * szTakeTime;
		int nMsgID;
		int nSenderAgent;
		int nRecvTime;
		int nMediaID;
		int nTakeTime;
		char * szRecvierAgent;
		int nRecvierAgent;
	} IMMediaST_t;

	typedef struct KcpMsgST {
		char dst_ip[32];
		int dst_port;
		int type;
		char uid[36];
		char sid[36];
		char uid_ex[36];
	} KcpMsgST_t;
	typedef struct ImCallVA {
		char dst_ip[32];
		int dst_port;
		int callType;
		char callid[64];
		int uid;
		int uid_ex;
		int sample;
	} ImCallVA_t;

	typedef struct MesTaskResult
	{
		char *result;
		int result_len;
		int errorCode;
		char errorMsg[64];
	}MesTaskResult_t;
	typedef struct ImMesTaskHandle
	{
		char task_cmd[64];
		int (*taskFunctionCall)(struct MesTaskResult *result_out,IMEventST_t *im,cJSON *cjson);
	}ImMesTaskHandle_t;
void onConnStaChange(int sta);
void onLoginSucc(char* szUserName,int nUserNameLen,char *szUserAgent,int nUserAgentLen,char *szUid,int nUid,char *szSid,int nSid,char *szAccessToken,int nAccessToken,char *szWebCtxPath, int nWebCtxPath);
void onLoginFail(char* szUserName,int len);
void onLogouSucc(char* szUserName,int len);
void onLogouFail(char* szUserName,int len);
void onLoginSta(char* szUserReason,int len);
void onNetworkSta(int sta);
void onRecvHeartBeat();

/************************************************************************/
/* 即时通信消息解析线程													*/
/************************************************************************/
void IMHandle(void *arg);

// 设置MesTask处理函数
int im_MesTask_addHandle(ImMesTaskHandle_t handle);
int sendMesProxyTaskResult(int channelID, char *task_id,int isSucc, char *result);


int sendImMsgToLocal(char *dst_uid,char *dst_mSessionID,char *ImMsgHandle,char *msg_ctx);

/** 消息撤回 **/
int sendImRetract(char *szRtJson, int *nRtJsonLen,char *dst_uid,char *dst_mSessionID,char *szMsgID);
/** 消息已读 **/
int sendImReaded(char *szRtJson, int *nRtJsonLen,char *dst_uid,char *dst_mSessionID,char *szMsgID);
/** 发送文本 **/
int sendImText(char *szRtJson, int *nRtJsonLen,char *dst_uid,char *dst_mSessionID,char *im_ctx);
/** 发送图片 **/
int sendImImg(char *szRtJson, int *nRtJsonLen,char *dst_uid,char *dst_mSessionID,char *im_mediaID);
/** 发送位置 **/
int sendImLoc(char *szRtJson, int *nRtJsonLen,char *dst_uid,char *dst_mSessionID,char *im_locX,char *im_locY,char *im_label);
/** 发送视频 **/
int sendImVideo(char *szRtJson, int *nRtJsonLen,char *dst_uid,char *dst_mSessionID,char *im_mediaID);
/** 发送音频 **/
int sendImAudio(char *szRtJson, int *nRtJsonLen,char *dst_uid,char *dst_mSessionID,char *im_mediaID);
/** 发送文件 **/
int sendImFile(char *szRtJson, int *nRtJsonLen,char *dst_uid,char *dst_mSessionID,char *im_mediaID);
/** 发送链接 **/
int sendImLink(char *szRtJson, int *nRtJsonLen,char *dst_uid,char *dst_mSessionID,char *im_url);
/** 发送事件 **/
int sendImEventMsg(char *szRtJson, int *nRtJsonLen,int channelID,char *src_uid,char *dst_uid,char *evt_name,char *evt_key,char *evt_obj);
/** 发送视频呼叫请求 **/
int sendCallin(char *szRtJson, int *nLen,char *dst_uid,ImCallVA_t *im);
/** 发送视频呼叫接收请求 **/
int sendAccept(char *szRtJson, int *nLen,char *dst_uid,ImCallVA_t *im);
/** 发送视频呼叫拒绝请求 **/
int sendReject(char *szRtJson, int *nLen,char *dst_uid,ImCallVA_t *im);
/** 发送视频通话结束请求 **/
int sendComplete(char *szRtJson, int *nLen,char *dst_uid,ImCallVA_t *im);

void onRecvEvent(IMEventST_t *pText);

void onRecvText(IMTextST_t *pText);

void onRecvLocation(IMLocationST_t *pLocation);

void onRecvImage(IMMediaST_t *pMedia);

void onRecvVoice(IMMediaST_t *pMedia);

void onRecvVideo(IMMediaST_t *pMedia);

void parseKcpMsg(KcpMsgST_t *kcpmsg, char *evtObjSTR);
void formatKcpMsg(char *kcpmsgSTR,KcpMsgST_t *kcpmsg);

#endif
